package com.example.ordersystem.controller;

import com.example.ordersystem.entity.Dish;
import com.example.ordersystem.entity.Order;
import com.example.ordersystem.service.DishService;
import com.example.ordersystem.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.stream.Collectors;

@Controller
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private DishService dishService;
    @Autowired
    private OrderService orderService;

    // 菜品库存预警页面
    @GetMapping("/stock-warning")
    public String stockWarning(Model model) {
        List<Dish> lowStockDishes = dishService.getAllDishes().stream()
                .filter(d -> d.getStock() != null && d.getStock() <= 5)
                .collect(Collectors.toList());
        model.addAttribute("lowStockDishes", lowStockDishes);
        return "stock-warning";
    }

    // 订单打印接口（返回订单详情JSON）
    @GetMapping("/print-orders")
    @ResponseBody
    public List<Order> printOrders() {
        return orderService.getAllOrders();
    }
} 